<?php
/**
 * Sharings View for Sharing World Component
 * 
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_4
 * @license		GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );

/**
 * Sharings View
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class CongregationViewProvince extends JView
{
	protected $state;
	protected $item;
	protected $form;

	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
		$this->state	= $this->get('State');
		$this->item		= $this->get('Item');
		$this->form		= $this->get('Form');

		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}

		$this->addToolbar();
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	protected function addToolbar()
	{
		JRequest::setVar('hidemainmenu', true);

		$user		= JFactory::getUser();
		$userId		= $user->get('id');
		$isNew		= ($this->item->p_id == 0);

		$canDo		= CongregationHelper::getActions();

		if($isNew)
		{
			JToolBarHelper::title(JText::_('New Province'), 'generic.png');
		}
		else
		{
			JToolBarHelper::title(JText::_('Edit Province'), 'generic.png');
		}

		// If not checked out, can save the item.
		if ($canDo->get('core.edit'))
		{
			JToolBarHelper::save('province.save');
		}
		if ($canDo->get('core.create'))
		{
			JToolBarHelper::save2new('province.save2new');
		}

		if (empty($this->item->id)) {
			JToolBarHelper::cancel('province.cancel');
		}
		else {
			JToolBarHelper::cancel('province.cancel', 'JTOOLBAR_CLOSE');
		}

	}

		
}
